* Firm organization with multiple establishments
* Appendix A: Tables A.2-A.6, 2012 cross-section

clear all 
set matsize 2000
set more off

capture log close
log using log/28_cmrh-cs_replication_firm.log, replace

********************************************************************************
********************************************************************************
* Use individual-level dataset

use data/CMRH_2012_p_layer-ind.dta, clear

*table A.2: distribution by layer
*****************************

tabstat tentgelt, by(layer) s(n mean sd p5 p10 q p90 p95)
tabstat d_educ, by(layer) s(n mean sd p5 p10 q p90 p95)
//	# obs.
tab layer, missing

********************************************************************************
********************************************************************************
* Use firm-level dataset

use data/CMRH_2012_cs_layer-unt.dta, clear

duplicates report untid jahr

*table A.3: statistics by layers
******************************
table count_mgmt_unt, c(n empl_unt mean empl_unt mean avg_wage median avg_wage)

*table A.4: fraction of firms with correct ordering
***************************************************
tabulate correctlyr count_mgmt_unt, col nofreq
tabulate correctlyr count_mgmt_unt [aweight=empl_unt], col nofreq
// # obs
tabulate correctlyr count_mgmt_unt
tabulate correctlyr count_mgmt_unt [aweight=empl_unt]
******************** end table A.4


*Table A.5: # employees are hierarchical
**************************************
gen h=.
*layer 1 firms
replace h=0 if count_mgmt_unt==1 & empl_lyr0~=. & empl_lyr1~=. 
replace h=1 if count_mgmt_unt==1 & empl_lyr0>=empl_lyr1 & empl_lyr0~=.
*layer 2 firms
replace h=0 if count_mgmt_unt==2 & empl_lyr0~=. & empl_lyr1~=. & empl_lyr2~=.
replace h=1 if count_mgmt_unt==2 & empl_lyr1>=empl_lyr2 & empl_lyr0>=empl_lyr1 & empl_lyr0~=.
*layer 3 firms
replace h=0 if count_mgmt_unt==3 & empl_lyr0~=. & empl_lyr1~=. & empl_lyr2~=. & empl_lyr3~=.
replace h=1 if count_mgmt_unt==3 & empl_lyr2>=empl_lyr3 & empl_lyr1>=empl_lyr2 & empl_lyr0>=empl_lyr1 & empl_lyr0~=.


gen h01 = (empl_lyr0>=empl_lyr1 & empl_lyr0~=.)
gen h12 = (empl_lyr1>=empl_lyr2 & empl_lyr1~=.)
gen h23 = (empl_lyr2>=empl_lyr3 & empl_lyr2~=.)

*
*fraction of firms satisfying hierarchy
*In each cell:
* - first element: number of obs in cell
* - second element: fraction of firms with 1

*data for table A.5
tabstat h01 h12 h23  if count_mgmt_unt>0, by(count_mgmt_unt) format(%12.3f) statistics(N mean)

count if h01 == 1 & h12 == 1 & count_mgmt_unt == 2
count if h01 == 1 & h12 == 1 & h23 == 1 & count_mgmt_unt == 3

drop  h- h23
******************** end table A.5


*Table A.6: wages are hierarchical
****************************************
gen h=.
*layer 1 firms
replace h=0 if count_mgmt_unt==1 & avg_wage_lyr0~=. & avg_wage_lyr1~=. 
replace h=1 if count_mgmt_unt==1 & avg_wage_lyr0<=avg_wage_lyr1 & avg_wage_lyr1~=.
*layer 2 firms
replace h=0 if count_mgmt_unt==2 & avg_wage_lyr0~=. & avg_wage_lyr1~=. & avg_wage_lyr2~=.
replace h=1 if count_mgmt_unt==2 & avg_wage_lyr1<=avg_wage_lyr2 & avg_wage_lyr0<=avg_wage_lyr1 & avg_wage_lyr2~=.
*layer 3 firms
replace h=0 if count_mgmt_unt==3 & avg_wage_lyr0~=. & avg_wage_lyr1~=. & avg_wage_lyr2~=. & avg_wage_lyr3~=.
replace h=1 if count_mgmt_unt==3 & avg_wage_lyr2<=avg_wage_lyr3 & avg_wage_lyr1<=avg_wage_lyr2 & avg_wage_lyr0<=avg_wage_lyr1 & avg_wage_lyr3~=.

*
gen h01 = (avg_wage_lyr0<=avg_wage_lyr1 & avg_wage_lyr1~=.)
gen h12 = (avg_wage_lyr1<=avg_wage_lyr2 & avg_wage_lyr2~=.)
gen h23 = (avg_wage_lyr2<=avg_wage_lyr3 & avg_wage_lyr3~=.)


*fraction of firms satisfying hierarchy
*In each cell:
* - first element: number of obs in cell
* - second element: fraction of firms with 1
*data for table A.6
tabstat h01 h12 h23  if count_mgmt_unt>0, by(count_mgmt_unt) format(%12.3f) statistics(N mean)

count if h01 == 1 & h12 == 1 & count_mgmt_unt == 2
count if h01 == 1 & h12 == 1 & h23 == 1 & count_mgmt_unt == 3

******************** end table A.6

log close

clear all
